﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.product
{
    public partial class goodsprice : System.Web.UI.Page
    {
        // Fields

        public string pronames = "";
        public string ps = "";

        public string yuan = info.info1("", "shophuobi");

        // Methods
        private void Bind()
        {
            string sql = "select * from DB_Pinpai where visible=1 and languages=" + info.languages("") + " order by pinpaiorder";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.propinpai.Items.Add(new ListItem(row["pinpainame"].ToString(), row["pinpaiid"].ToString()));
                }
            }
        }

        private void Display(string parentid, string space)
        {
            string sql = "Select * From DB_Productclass Where parentid =" + parentid + " and languages=" + info.languages("") + " Order By classorder";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.typeid.Items.Add(new ListItem(space + "" + row["classname"].ToString() + "", "" + row["classid"].ToString() + ""));
                    this.Display(row["classid"].ToString(), "|-" + space);
                }
            }
        }

        protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            if (base.Request.Form["proname"] != null)
            {
                string str3;
                if (base.Request.Form["proname"] != null)
                {
                    str3 = base.Request.Form["proname"];
                }
                else
                {
                    str3 = "0";
                }
                if (str3 != "0")
                {
                    long num3;
                    string[] strArray = str3.ToString().Split(new char[] { ',' });
                    for (int i = 0; i <= (strArray.Length - 1); i++)
                    {
                        num3 = Convert.ToInt64(base.Request.Form["proprice5_" + strArray[i]]);
                        long num = Convert.ToInt64((float)(num3 + ((num3 * Convert.ToSingle(base.Request.Form["proprice3_" + strArray[i]])) / 100f)));
                        long num2 = Convert.ToInt64((float)(num3 + ((num3 * Convert.ToSingle(base.Request.Form["proprice1_" + strArray[i]])) / 100f)));
                        SQLAccess.DoSql(string.Concat(new object[] { "update DB_Shoppro set proprice5=", num3, ", proprice1=", num2, ",proprice3=", num, ",price1=", base.Request.Form["proprice3_" + strArray[i]], ",price2=", base.Request.Form["proprice1_" + strArray[i]], " where proid=", strArray[i], "" }));
                    }
                    string sql = "select * from DB_memberank order by rankid asc";
                    DataTable table = SQLAccess.GreatDs(sql).Tables[0];
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            for (int j = 0; j <= (strArray.Length - 1); j++)
                            {
                                num3 = Convert.ToInt64(base.Request.Form["proprice5_" + strArray[j]]);
                                long num4 = Convert.ToInt64((float)(num3 + ((num3 * Convert.ToSingle(base.Request.Form["price" + row["rankid"].ToString() + "_" + strArray[j]])) / 100f)));
                                SQLAccess.DoSql(string.Concat(new object[] { "update DB_Memberprice set price=", num4, ",price1=", base.Request.Form["price" + row["rankid"].ToString() + "_" + strArray[j]], " where productid=", strArray[j], " and rankid=", row["rankid"].ToString(), "" }));
                            }
                        }
                    }
                    base.Response.Write("<script language=javascript>alert('修改成功！');window.location.href='goodsprice.aspx';</script>");
                    base.Response.End();
                }
                else
                {
                    base.Response.Write("<script language=javascript>alert('未选择产品！');window.history.go(-1);</script>");
                    base.Response.End();
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>alert('请选择产品！');window.history.go(-1);</script>");
                base.Response.End();
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            string sql = "select * from DB_Shoppro where visible=1 and languages=" + info.languages("") + " ";
            if (this.typeid.SelectedValue.ToString() != "0")
            {
                sql = sql + " and typeid in(" + re.returntype("0", this.typeid.SelectedValue.ToString(), info.languages("")) + ")";
            }
            if (this.propinpai.SelectedValue.ToString() != "0")
            {
                sql = sql + " and propinpai=" + this.propinpai.SelectedValue.ToString() + "";
            }
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.tables.Visible = true;
                int num = 0;
                this.pronames = this.pronames + "说明：价格修改是在进货价的基础上进行增加百分之几或减少百分之几，要减少的话请在数字前加-号(负号)。<br/>";
                string pronames = this.pronames;
                this.pronames = pronames + "<table width=100% border='0' cellpadding='0' cellspacing='1'><tr bgcolor='#E2E7EB'><td width=5%></td><td class='title01'>商品名称</td><td class='title01' width=10%>进货价(" + this.yuan + ")</td><td class='title01' width=12%>市场价(" + this.yuan + ")</td><td class='title01' width=12%>本店价(" + this.yuan + ")</td>";
                string str3 = "Select * From DB_memberank";
                DataTable table2 = SQLAccess.GreatDs(str3).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    foreach (DataRow row in table2.Rows)
                    {
                        string str5 = this.pronames;
                        this.pronames = str5 + "<td class='title01' width=12%>" + row["rank"].ToString() + "(" + this.yuan + ")</td>";
                    }
                }
                this.pronames = this.pronames + "</tr><tr>";
                foreach (DataRow row2 in table.Rows)
                {
                    object obj2 = this.pronames;
                    this.pronames = string.Concat(new object[] { obj2, "<td><input id='Checkbox", num, "' name='proname' value='", row2["proid"].ToString(), "' type='checkbox' />" });
                    this.pronames = this.pronames + "<td>" + row2["proname"].ToString() + "</td>";
                    string str6 = this.pronames;
                    this.pronames = str6 + "<td><input id='proprice5_" + row2["proid"].ToString() + "' name='proprice5_" + row2["proid"].ToString() + "' value='" + row2["proprice5"].ToString() + "' size=2 /></td>";
                    string str7 = this.pronames;
                    this.pronames = str7 + "<td><input id='proprice3_" + row2["proid"].ToString() + "' onkeyup='pricenum(proprice5_" + row2["proid"].ToString() + ",this,proprice3value_" + row2["proid"].ToString() + ")' name='proprice3_" + row2["proid"].ToString() + "' value='" + row2["price1"].ToString() + "' size=1 />% <font color=#666666>(<span id=proprice3value_" + row2["proid"].ToString() + ">" + row2["proprice3"].ToString() + "</span>)</font></td>";
                    string str8 = this.pronames;
                    this.pronames = str8 + "<td><input id='proprice1_" + row2["proid"].ToString() + "' onkeyup='pricenum(proprice5_" + row2["proid"].ToString() + ",this,proprice1value_" + row2["proid"].ToString() + ")' name='proprice1_" + row2["proid"].ToString() + "' value='" + row2["price2"].ToString() + "' size=1 />% <font color=#666666>(<span id=proprice1value_" + row2["proid"].ToString() + ">" + row2["proprice1"].ToString() + "</span>)</font></td>";
                    DataTable table3 = SQLAccess.GreatDs("select DB_Memberprice.price,DB_Memberprice.price1,DB_memberank.* from DB_Memberprice,DB_memberank where DB_memberank.rankid=DB_Memberprice.rankid and  productid=" + row2["proid"] + "").Tables[0];
                    if (table3.Rows.Count > 0)
                    {
                        foreach (DataRow row3 in table3.Rows)
                        {
                            string str9 = this.pronames;
                            this.pronames = str9 + "<td><input id='price" + row3["rankid"].ToString() + "_" + row2["proid"].ToString() + "' name='price" + row3["rankid"].ToString() + "_" + row2["proid"].ToString() + "' onkeyup='pricenum(proprice5_" + row2["proid"].ToString() + ",this,pricevalue" + row3["rankid"].ToString() + "_" + row2["proid"].ToString() + ")' value='" + row3["price1"].ToString() + "' size=1 />% <font color=#666666>(<span id=pricevalue" + row3["rankid"].ToString() + "_" + row2["proid"].ToString() + ">" + row3["DB_Memberprice.price"].ToString() + "</span>)</font></td>";
                        }
                    }
                    num++;
                    this.pronames = this.pronames + "</tr>";
                }
                this.pronames = this.pronames + "</table>";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            if (!base.IsPostBack)
            {
                this.Display("0", "|--");
                this.Bind();
            }
        }

    }
}